Public Class DataGridViewDatePickCell
    Inherits DataGridViewTextBoxCell

    Dim dgvOwningColumn As DataGridViewDatePickColumn


    Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)


        Dim cmbEditCtrl As DataGridViewDatePickEditControl


        dgvOwningColumn = DirectCast(Me.OwningColumn, DataGridViewDatePickColumn)
        cmbEditCtrl = DirectCast(DataGridView.EditingControl, DataGridViewDatePickEditControl)

        If String.IsNullOrEmpty(CStr(initialFormattedValue)) Then
            cmbEditCtrl.Value = Now
        Else
            cmbEditCtrl.Value = DateTime.Parse(CStr(initialFormattedValue))
        End If



    End Sub

    Public Overrides ReadOnly Property FormattedValueType() As System.Type
        Get
            Return GetType(String)
        End Get
    End Property


    Public Overrides ReadOnly Property ValueType() As System.Type
        Get
            Return GetType(Date)
        End Get
    End Property

    Public Overrides Function ParseFormattedValue(ByVal formattedValue As Object, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter, ByVal valueTypeConverter As System.ComponentModel.TypeConverter) As Object
        If formattedValue Is Nothing Then Return Nothing
        Return DateTime.Parse(CStr(formattedValue))

    End Function

    Public Overrides ReadOnly Property EditType() As Type
        Get
            Return GetType(DataGridViewDatePickEditControl)
        End Get
    End Property

End Class
